/**
    package: learn-go
    filename: main
    author: diogo@gmail.com
    time: 2021/11/29 10:35
**/
package main

import (
	"fmt"

	"github.com/goinggo/mapstructure"
)

type Person struct {
	Name string
	Age  int
}

func MapToStruct() {
	mapInstance := make(map[string]interface{})
	mapInstance["Name"] = "liang637210"
	mapInstance["Age"] = 28

	var person Person
	//将 map 转换为指定的结构体
	if err := mapstructure.Decode(mapInstance, &person); err != nil {
		fmt.Println(err)
	}
	fmt.Printf("map2struct后得到的 struct 内容为:%v", person)
}

func main() {
	MapToStruct()
}
